package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 客户老人Controller
 * 
 * @author gziqi
 * @date 2025-01-18
 */
@Api(tags = "客户老人管理")
@RestController
@RequestMapping("/nursing/familyMemberElder")
public class FamilyMemberElderController extends BaseController
{
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    /**
     * 查询客户老人列表
     */
    @ApiOperation("查询客户老人列表")
    @PreAuthorize("@ss.hasPermi('nursing:familyMemberElder:list')")
    @GetMapping("/list")
    public TableDataInfo<List<FamilyMemberElder>> list(@ApiParam("客户老人查询条件") FamilyMemberElder familyMemberElder)
    {
        startPage();
        List<FamilyMemberElder> list = familyMemberElderService.selectFamilyMemberElderList(familyMemberElder);
        return getDataTable(list);
    }

    /**
     * 导出客户老人列表
     */
    @ApiOperation("导出客户老人列表")
    @PreAuthorize("@ss.hasPermi('nursing:familyMemberElder:export')")
    @Log(title = "客户老人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@ApiParam(value = "客户老人查询条件") HttpServletResponse response, FamilyMemberElder familyMemberElder)
    {
        List<FamilyMemberElder> list = familyMemberElderService.selectFamilyMemberElderList(familyMemberElder);
        ExcelUtil<FamilyMemberElder> util = new ExcelUtil<FamilyMemberElder>(FamilyMemberElder.class);
        util.exportExcel(response, list, "客户老人数据");
    }

    /**
     * 获取客户老人详细信息
     */
    @ApiOperation("获取客户老人详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:familyMemberElder:query')")
    @GetMapping(value = "/{id}")
    public R<FamilyMemberElder> getInfo(@ApiParam("客户老人ID") @PathVariable("id") Long id)
    {
        return R.ok(familyMemberElderService.selectFamilyMemberElderById(id));
    }

    /**
     * 新增客户老人
     */
    @ApiOperation("新增客户老人")
    @PreAuthorize("@ss.hasPermi('nursing:familyMemberElder:add')")
    @Log(title = "客户老人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam("客户老人信息") @RequestBody FamilyMemberElder familyMemberElder)
    {
        return toAjax(familyMemberElderService.insertFamilyMemberElder(familyMemberElder));
    }

    /**
     * 修改客户老人
     */
    @ApiOperation("修改客户老人")
    @PreAuthorize("@ss.hasPermi('nursing:familyMemberElder:edit')")
    @Log(title = "客户老人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam("客户老人信息") @RequestBody FamilyMemberElder familyMemberElder)
    {
        return toAjax(familyMemberElderService.updateFamilyMemberElder(familyMemberElder));
    }

    /**
     * 删除客户老人
     */
    @ApiOperation("删除客户老人")
    @PreAuthorize("@ss.hasPermi('nursing:familyMemberElder:remove')")
    @Log(title = "客户老人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("客户老人ID数组") @PathVariable Long[] ids)
    {
        return toAjax(familyMemberElderService.deleteFamilyMemberElderByIds(ids));
    }
}
